package com.csii.adhoc.util;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.convert.ConvertException;
import cn.hutool.core.convert.impl.CollectionConverter;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @description:
 * @author: panChuanJiang
 * @create: 2021-06-22 09:33
 */
public class ConvertUtils {
    public ConvertUtils() {
    }

    public static <T> T convert(Type type, Object value) throws ConvertException {
        return Convert.convert(type, value);
    }


    public static <T> IPage<T> convertIPage(Type type, IPage iPage) throws ConvertException {
        IPage iPageVO = Convert.convert(IPage.class, iPage);
        iPageVO.setRecords((List)(new CollectionConverter(ArrayList.class, type)).convert(iPage.getRecords(), (Collection)null));
        return iPageVO;
    }

    public static <T> List<T> convertList(Class<T> elementType, Object value) throws ConvertException {
        return Convert.toList(elementType, value);
    }
}
